package com.jl.jlapp.mvp.fragment;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemChildClickListener;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemClickListener;
import com.chad.library.adapter.base.BaseQuickAdapter.RequestLoadMoreListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.MyOrderListAdapter;
import com.jl.jlapp.eneity.CancleOrderModel;
import com.jl.jlapp.eneity.CopyOrderShoppingCartModel;
import com.jl.jlapp.eneity.Order;
import com.jl.jlapp.eneity.OrderListModel;
import com.jl.jlapp.eneity.OrderListModel.ResultDataBean;
import com.jl.jlapp.mvp.activity.EvaluationDetailActivity;
import com.jl.jlapp.mvp.activity.LoginActivity;
import com.jl.jlapp.mvp.activity.MyOrderListActivity;
import com.jl.jlapp.mvp.activity.OrderDetailActivity;
import com.jl.jlapp.mvp.activity.OrderTracingActivity;
import com.jl.jlapp.mvp.activity.PayOrderActivity;
import com.jl.jlapp.mvp.activity.ShouldEvaluationActivity;
import com.jl.jlapp.mvp.activity.UnderlineActivity;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.nets.Transformer;
import com.jl.jlapp.popu.ClearHistorySearhPopu;
import com.jl.jlapp.utils.Tools;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import java.util.ArrayList;
import java.util.List;

public class MyOrderListFragment extends Fragment implements RequestLoadMoreListener {
    private static final int PAGE_SIZE = 10;
    private int TOTAL_COUNTER = 0;
    ClearHistorySearhPopu clearHistorySearhPopu;
    private int delayMillis = 1000;
    private int mCurrentCounter = 0;
    @BindView(R.id.swipeLayout)
    SwipeRefreshLayout mSwipeRefreshLayout;
    MyOrderListActivity myOrderListActivity;
    MyOrderListAdapter myOrderListAdapter;
    @BindView(R.id.my_order_recycler_view)
    RecyclerView myOrderListView;
    List<OrderListModel.ResultDataBean> orderListDataBeans;
    int orderState = -1;
    ArrayList<Order> orders;
    private ProgressDialog progressDialog;
    List<OrderListModel.ResultDataBean> shouldShowDataBeanList;
    int userId = 0;
    View view;

    public void buildProgressDialog() {
        if (this.progressDialog == null) {
            this.progressDialog = new ProgressDialog(getContext());
            this.progressDialog.setProgressStyle(0);
        }
        this.progressDialog.setMessage("加载中");
        this.progressDialog.setCancelable(true);
        this.progressDialog.show();
    }

    public void buyAgainClick(Integer paramInteger) {
        Net.get().buyAgain(paramInteger.intValue(), this.userId)
                .compose(Transformer.<CopyOrderShoppingCartModel>switchSchedulers())
                .subscribe(new CommonObserver<CopyOrderShoppingCartModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(CopyOrderShoppingCartModel copyOrderShoppingCartModel) {

                    }
                });
    }

    public void cancelProgressDialog() {
        if ((this.progressDialog != null) && (this.progressDialog.isShowing())) {
            this.progressDialog.dismiss();
        }
    }

    public void cancleOrder(Integer paramInteger1, Integer paramInteger2, Integer paramInteger3) {
        Net.get().cancleOrder(paramInteger2.intValue(), paramInteger1.intValue(), paramInteger3.intValue())
                .compose(Transformer.<CancleOrderModel>switchSchedulers())
                .subscribe(new CommonObserver<CancleOrderModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(CancleOrderModel cancleOrderModel) {

                    }
                });
    }

    public void getOrderList(Integer paramInteger) {
        Net.get().getOrderList(paramInteger.intValue())
                .compose(Transformer.<OrderListModel>switchSchedulers())
                .subscribe(new CommonObserver<OrderListModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(OrderListModel orderListModel) {

                    }
                });
    }

    public void getShouldShowDataListByOrderState(int paramInt1, int paramInt2) {
        if (this.shouldShowDataBeanList == null) {
            this.shouldShowDataBeanList = new ArrayList();
        }
        this.shouldShowDataBeanList.clear();
        ArrayList<OrderListModel.ResultDataBean> localArrayList = new ArrayList();
        int i = 0;
        if (i < this.orderListDataBeans.size()) {
            if (this.orderState == -1) {
                localArrayList.add(this.orderListDataBeans.get(i));
            } else {
                i += 1;
                if (this.orderState == 6) {
                    if ((((OrderListModel.ResultDataBean) this.orderListDataBeans.get(i)).getOrderState() == 6) || (((OrderListModel.ResultDataBean) this.orderListDataBeans.get(i)).getOrderState() == 7) || (((OrderListModel.ResultDataBean) this.orderListDataBeans.get(i)).getOrderState() == 8) || (((OrderListModel.ResultDataBean) this.orderListDataBeans.get(i)).getOrderState() == 10)) {
                        localArrayList.add(this.orderListDataBeans.get(i));
                    }
                } else if (this.orderState == 2) {
                    if (((OrderListModel.ResultDataBean) this.orderListDataBeans.get(i)).getOrderState() == 2) {
                        localArrayList.add(this.orderListDataBeans.get(i));
                    }
                } else if (((OrderListModel.ResultDataBean) this.orderListDataBeans.get(i)).getOrderState() == this.orderState) {
                    localArrayList.add(this.orderListDataBeans.get(i));
                }
            }
        }
        if ((localArrayList.size() > paramInt1) && (localArrayList.size() > paramInt1 + paramInt2)) {
            i = 0;
        }
        while (i < paramInt1 + paramInt2) {
            this.shouldShowDataBeanList.add(localArrayList.get(i));
            i += 1;
            if ((localArrayList.size() > paramInt1) && (localArrayList.size() <= paramInt1 + paramInt2)) {
                for (int i1 = 0; i1 < localArrayList.size(); i1++) {
                    this.shouldShowDataBeanList.add(localArrayList.get(i1));
                }
            }
        }
        this.TOTAL_COUNTER = localArrayList.size();
    }

    public List<OrderListModel.ResultDataBean> getShouldShowDataListByOrderState2(int paramInt1, int paramInt2) {
        ArrayList<OrderListModel.ResultDataBean> localArrayList1 = new ArrayList();
        ArrayList<OrderListModel.ResultDataBean> localArrayList2 = new ArrayList();
        int i = 0;
        if (i < this.orderListDataBeans.size()) {
            if (this.orderState == -1) {
                localArrayList1.add(this.orderListDataBeans.get(i));
            } else if (this.orderState == 6) {
                if ((((OrderListModel.ResultDataBean) this.orderListDataBeans.get(i)).getOrderState() == 6) || (((OrderListModel.ResultDataBean) this.orderListDataBeans.get(i)).getOrderState() == 7) || (((OrderListModel.ResultDataBean) this.orderListDataBeans.get(i)).getOrderState() == 8) || (((OrderListModel.ResultDataBean) this.orderListDataBeans.get(i)).getOrderState() == 10)) {
                    localArrayList1.add(this.orderListDataBeans.get(i));
                }
            } else if (this.orderState == 2) {
                if (((OrderListModel.ResultDataBean) this.orderListDataBeans.get(i)).getOrderState() == 2) {
                    localArrayList1.add(this.orderListDataBeans.get(i));
                }
            } else if (((OrderListModel.ResultDataBean) this.orderListDataBeans.get(i)).getOrderState() == this.orderState) {
                localArrayList1.add(this.orderListDataBeans.get(i));
            }
        }
        if ((localArrayList1.size() > paramInt1) && (localArrayList1.size() > paramInt1 + paramInt2)) {
            i = paramInt1;
        }
        while (i < paramInt1 + paramInt2) {
            localArrayList2.add(localArrayList1.get(i));
            i += 1;
            if ((localArrayList1.size() > paramInt1) && (localArrayList1.size() <= paramInt1 + paramInt2)) {
                while (paramInt1 < localArrayList1.size()) {
                    localArrayList2.add(localArrayList1.get(paramInt1));
                    paramInt1 += 1;
                }
            }
        }
        return localArrayList2;
    }

    public void onAttach(Activity paramActivity) {
        super.onAttach(paramActivity);
        this.myOrderListActivity = ((MyOrderListActivity) getActivity());
        this.orderState = this.myOrderListActivity.orderState;
    }

    public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
        this.view = paramLayoutInflater.inflate(R.layout.fragment_my_order_list, null, false);
        ButterKnife.bind(this, this.view);
        Log.d("aaaaaaaaMyOrder", "onCreateView");
        this.mSwipeRefreshLayout.setEnabled(false);
        return this.view;
    }

    public void onLoadMoreRequested() {
        this.mSwipeRefreshLayout.setEnabled(false);
        if (this.myOrderListAdapter.getData().size() < 10) {
            this.myOrderListAdapter.loadMoreEnd(false);
            return;
        }
        if (this.mCurrentCounter >= this.TOTAL_COUNTER) {
            this.myOrderListAdapter.loadMoreEnd(false);
            return;
        }
        new Handler().postDelayed(new Runnable() {
            public void run() {
                MyOrderListFragment.this.myOrderListAdapter.addData(MyOrderListFragment.this.getShouldShowDataListByOrderState2(MyOrderListFragment.this.myOrderListAdapter.getData().size(), 10));
                MyOrderListFragment.this.myOrderListAdapter.loadMoreComplete();
                MyOrderListFragment.this.mSwipeRefreshLayout.setEnabled(true);
            }
        }, this.delayMillis);
    }

    public void onResume() {
        super.onResume();
        Log.d("aaaaaaaaMyOrder", "onResume");
        this.userId = getContext().getSharedPreferences("JLAppData", 0).getInt("userId", 0);
        if (this.userId > 0) {
            buildProgressDialog();
            getOrderList(Integer.valueOf(this.userId));
            return;
        }
        Toast.makeText(getContext(), "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(getContext(), LoginActivity.class));
    }

    public void setAdapter() {
        Log.d("aaaaaaaaMyOrder", "setAdapter");
        if (this.myOrderListAdapter == null) {
            this.myOrderListView.setLayoutManager(new LinearLayoutManager(getActivity()));
            this.myOrderListAdapter = new MyOrderListAdapter(R.layout.my_order_list_item, this.shouldShowDataBeanList);
            this.myOrderListAdapter.setOnLoadMoreListener(this, this.myOrderListView);
            this.myOrderListView.setAdapter(this.myOrderListAdapter);
        } else {
            this.mCurrentCounter = this.myOrderListAdapter.getData().size();
            Log.d("aaaaaaaaaaaaref", "getData:" + this.myOrderListAdapter.getData().size());
            this.myOrderListAdapter.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                    Intent intent = new Intent(MyOrderListFragment.this.getActivity(), OrderDetailActivity.class);
                    intent.putExtra("orderId", ((OrderListModel.ResultDataBean) MyOrderListFragment.this.shouldShowDataBeanList.get(paramAnonymousInt)).getId());
                    MyOrderListFragment.this.startActivity(intent);
                }
            });
            this.myOrderListAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
                public void onItemChildClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, final int paramAnonymousInt) {
                    TextView my_order_item_bottom_btn1 = paramAnonymousView.findViewById(R.id.my_order_item_bottom_btn1);
                    TextView localTextView = (TextView) paramAnonymousView.findViewById(R.id.my_order_item_bottom_btn2);
                    String trim = my_order_item_bottom_btn1.getText().toString().trim();
                    Tools.addActivity(MyOrderListFragment.this.getActivity());
                    if (((OrderListModel.ResultDataBean) MyOrderListFragment.this.shouldShowDataBeanList.get(paramAnonymousInt)).getPayType() != 0) {
                    }
                    Intent intent = new Intent(MyOrderListFragment.this.getContext(), PayOrderActivity.class);
                    intent.putExtra("payMoney", ((OrderListModel.ResultDataBean) MyOrderListFragment.this.shouldShowDataBeanList.get(paramAnonymousInt)).getOrderPresentPrice() + ((OrderListModel.ResultDataBean) MyOrderListFragment.this.shouldShowDataBeanList.get(paramAnonymousInt)).getPostage());
                    intent.putExtra("orderId", ((OrderListModel.ResultDataBean) MyOrderListFragment.this.shouldShowDataBeanList.get(paramAnonymousInt)).getId());
                    intent.putExtra("orderNo", ((OrderListModel.ResultDataBean) MyOrderListFragment.this.shouldShowDataBeanList.get(paramAnonymousInt)).getOrderNo());
                    intent.putExtra("postagePayType", ((OrderListModel.ResultDataBean) MyOrderListFragment.this.shouldShowDataBeanList.get(paramAnonymousInt)).getPostagePayType());
                    MyOrderListFragment.this.startActivity(intent);
                    if (!trim.equals("支付")) {
                    }
                    if (!trim.equals("订单跟踪")) {
                    }
                    if (!trim.equals("再次购买")) {
                    }
                    Intent mIntent = new Intent(MyOrderListFragment.this.getContext(), OrderTracingActivity.class);
                    mIntent.putExtra("orderId", MyOrderListFragment.this.shouldShowDataBeanList.get(paramAnonymousInt).getId());
                    mIntent.putExtra("orderState", "待支付");
                    mIntent.putExtra("orderState", "待发货");
                    mIntent.putExtra("orderState", "待收货");
                    mIntent.putExtra("orderState", "已完成");
                    mIntent.putExtra("orderState", "已取消");
                    mIntent.putExtra("orderState", "已关闭");
                    mIntent.putExtra("orderState", "售后中");
                    mIntent.putExtra("orderState", "已退货退款");
                    mIntent.putExtra("orderState", "已换货");
                    mIntent.putExtra("orderState", "已支付，正在审核");
                    mIntent.putExtra("orderState", "关闭售后");


                    if ("评价晒单".equals(localTextView.getText().toString().trim())) {
                        Intent intent1 = new Intent(MyOrderListFragment.this.getContext(), ShouldEvaluationActivity.class);
                        intent1.putExtra("orderId", ((OrderListModel.ResultDataBean) MyOrderListFragment.this.shouldShowDataBeanList.get(paramAnonymousInt)).getId());
                        MyOrderListFragment.this.startActivity(intent1);
                        return;
                    }
                    if ("评价详情".equals(localTextView.getText().toString().trim())) {
                        Intent intent1 = new Intent(MyOrderListFragment.this.getActivity(), EvaluationDetailActivity.class);
                        intent1.putExtra("orderId", ((OrderListModel.ResultDataBean) MyOrderListFragment.this.shouldShowDataBeanList.get(paramAnonymousInt)).getId());
                        MyOrderListFragment.this.startActivity(intent1);
                        return;
                    }
                    if (!"确认收货".equals(localTextView.getText().toString().trim())) {
                    }
                    MyOrderListFragment.this.clearHistorySearhPopu = new

                            ClearHistorySearhPopu(MyOrderListFragment.this.getContext(), new

                            OnClickListener() {
                                public void onClick(View paramAnonymous2View) {
                                    MyOrderListFragment.this.clearHistorySearhPopu.dismiss();
                                    MyOrderListFragment.this.cancleOrder(Integer.valueOf(MyOrderListFragment.this.userId), Integer.valueOf(((OrderListModel.ResultDataBean) MyOrderListFragment.this.shouldShowDataBeanList.get(paramAnonymousInt)).getId()), Integer.valueOf(3));
                                }
                            }, Integer.valueOf(5));
                    MyOrderListFragment.this.clearHistorySearhPopu.showAtLocation(MyOrderListFragment.this.

                            getActivity().

                            findViewById(R.id.my_order_list_page), 17, 0, 0);
                }
            });
            this.myOrderListAdapter.notifyDataSetChanged();
        }
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/fragment/MyOrderListFragment.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */